﻿<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="SaleModiApply_Grid.aspx.vb" Inherits="Slxt.SaleModiApply_Grid"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>Demo_Main</title>
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
		<LINK href="/_grid/map_grid.css" type="text/css" rel="stylesheet">
		<LINK href="/_nav/menu.css" type="text/css" rel="stylesheet">
		<script language="javascript" src="/_common/scripts/global.js"></script>
		<link rel="stylesheet" type="text/css" href="/_forms/styles/form.css">
		<link rel="stylesheet" type="text/css" href="/_controls/find/find.css">
		<link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
		<link rel="stylesheet" type="text/css" href="/_grid/map_grid.css">
		<script language="javascript" src="/_controls/settings.aspx"></script>
		<script language="javascript" src="/_controls/util/util.js"></script>
		<script language="javascript" src="/_controls/datetime/date.js"></script>
		<script language="javascript" src="/_controls/number/number.js"></script>
		<script language="javascript" src="/_nav/menu.js"></script>
		<script language="javascript" src="/MyWorkflow/workflow.js"></script>
		<script language="javascript" src="/Slxt/js/Public.js"></script>
		<script language="javascript" src="/PubProject/Js/Public.js"></script>
		<script language="javascript">
		    var IsHaveRgSq="0";
		    var IsHaveHtSq="0";
		    var IsHaveBgSp="0";
		    function window.onload()
		    {
		        var strIsHaveRight = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","IsHaveSpRight","01010303","16");
                if(strIsHaveRight=="1")
                {
                    IsHaveRgSq="1";
                }
                strIsHaveRight = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","IsHaveSpRight","01010304","16");
                if(strIsHaveRight=="1")
                {
                    IsHaveHtSq="1";
                }
		        strIsHaveRight = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","IsHaveSpRight","01010305","10");
                if(strIsHaveRight=="1")
                {
                    IsHaveBgSp="1";
                }

		    } 
		     
			// open 打开修改窗口
			function openModiWin()
			{
				// 选中行对象数组
				var oTr = appGrid.frameElement.getSelected();
				if (!oTr) return;
				
				// 打开第一个选中行
				var sFuncid;
				var strIsHaveRight = "0";   
				if (oTr[0].SaleType == "定单")
				{
				    sFuncid = "01010303";
				    strIsHaveRight=IsHaveRgSq;
				}
				else
				{
				    sFuncid = "01010304";
				    strIsHaveRight=IsHaveHtSq;
				}				
				
				var sType = oTr[0].ApplyType;
				var sMode, sPath;
				var sApproveState = oTr[0].ApproveState;                                                                   
                         
               if(strIsHaveRight=="1")
               { 
                   if (sApproveState == "待审批"&&oTr[0].ApplyState!="作废")
				    {
				        sMode = "2";
				        //判断工作流中是否已经发起审批
	                    var strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","VerifyTradeIsFqSp",oTr[0].oid,"");
	                    if(strReturn!="PASS")
	                    {
	                       sMode ="3";			                
	                    }	
				    }
				    else
				    {
				        sMode = "3";
				    }	          
               }
               else
               {
                   sFuncid = "01010305";
                     sMode = "3";
               }
                            
				var iWidth=800;
				var iHeight=600;			
				switch (sType)
				{
                    case "换房":
				        sPath = "SaleModiApply_Hf_Edit.aspx?mode=" + sMode + "&oid=" + escape(oTr[0].oid) +  "&SaleGUID=" + escape(oTr[0].SaleGUID) + "&funcid=" + escape(sFuncid) +"&SaleType=" + escape(oTr[0].SaleType);
				    break;
				    case "退房":
				       sPath = "SaleModiApply_Tf_Edit.aspx?mode=" + sMode + "&oid=" + escape(oTr[0].oid) +  "&SaleGUID=" + escape(oTr[0].SaleGUID) + "&funcid=" + escape(sFuncid) +"&SaleType=" + escape(oTr[0].SaleType);
				    break;
				    case "变更价格":
					   sPath = "SaleModiApply_ChgPrice_Edit.aspx?mode=" + sMode + "&oid=" + escape(oTr[0].oid) +  "&SaleGUID=" + escape(oTr[0].SaleGUID) + "&funcid=" + escape(sFuncid) +"&SaleType=" + escape(oTr[0].SaleType);
				   break;
				   case "增减权益人":
				      sPath = "SaleModiApply_ChgCstName_Edit.aspx?mode=" + sMode + "&oid=" + escape(oTr[0].oid) +  "&SaleGUID=" + escape(oTr[0].SaleGUID) + "&funcid=" + escape(sFuncid) +"&SaleType=" + escape(oTr[0].SaleType);
				      break;
				  case "特批折扣":
				      sPath = "SaleModiApply_Tpzk_Edit.aspx?mode=" + sMode + "&oid=" + escape(oTr[0].oid) + "&SaleGUID=" + escape(oTr[0].SaleGUID) + "&funcid=" + escape(sFuncid) + "&ApplyType=" + escape("特批折扣") + "&SaleType=" + escape(oTr[0].SaleType);
				      iWidth = 1150;
				      iHeight = 700;
				      break;
				   default :
				     iWidth=600;
				     iHeight=450;
				     sPath = "SaleModiApply_Edit.aspx?mode=" + sMode + "&oid=" + escape(oTr[0].oid) +  "&SaleGUID=" + escape(oTr[0].SaleGUID) + "&funcid=" + escape(sFuncid) +"&SaleType=" + escape(oTr[0].SaleGUID);
				   break;				  
				} 
				OpenWin(sPath,iWidth,iHeight,0);
			}
		
			//取消审批
			function CancelApprove()
			{	
				// 选中行对象数组
				var oTr = appGrid.frameElement.getSelected();
				if (!oTr) return;
				
				if(confirm("确实要取消审批所选中的记录吗?"))
				{
					// 如果已经被执行，则不允许取消审核
					if(oTr[0].ApplyState == "已执行")
					{
						alert("已经执行,不允许取消审核！");
						return;
					}
					
					var sType = oTr[0].ApplyType;
				    if(sType != "其它变更") {
                        
				        
                        var strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","VerifyTradeIsSameSp", oTr[0].oid,"",oTr[0].SaleGUID);
                        if (strReturn!="PASS") 
                        {
                            var strRtn=strReturn.split("|");
                            if(strRtn[0]=="NOPASS")
                            {
                                alert("已存在“" +strRtn[2]+ "”的“" +strRtn[1]+ "”变更申请单，不允许取消审批！");
                                return;                              
                            }
                            else
                            {
                                alert("系统错误，请稍后重试！")
                                return;                              
                            }
                        }
                        //如果当前变更的申请类型为“变更价格”或者“特批折扣”，并且该销售单为合同
                        //如果该销售单做了面积补差，则提示“该变更对应的销售单已经做了面积补差，不允许取消审批！”，不执行后续操作
                       if ((sType == "变更价格" || sType === "特批折扣") && oTr[0].SaleType == "合同")
                       {
                            var strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","VerifyBcJbDate",oTr[0].SaleGUID,"");
                            if(strReturn=="NOPASS")
                            {
                              alert("该变更对应的销售单已经做了面积补差，不允许取消审批！");
                              return;
                            }
                       }
                    }
					
					strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","CancelApprove",oTr[0].oid, "");

					if (strReturn == "OK") 
					{
						appGrid.frameElement.Query();							
						alert("取消审批成功！");
					}
					else
					{
						alert("取消审批失败！");
					}
				}
			}
			
			//审批
			function Approve() {
			  
				var oTr = appGrid.frameElement.getSelected();
				if (!oTr) return;
				
				var sType = oTr[0].ApplyType;
				var sApproveState = oTr[0].ApproveState;
				var sApplyState = oTr[0].ApplyState;
				
				if (sApplyState == "作废")
				{
				    alert("申请记录状态为作废，不允许进行审批操作！");
				    return false;
				}
				
				if (sApproveState == "审批中" || sApproveState == "已审批")
				{
				    alert("审批状态为" + sApproveState + "，不允许进行审批操作！");
				    return false;
				}
				
				if (sApproveState == "待审批")
				{
					//判断工作流中是否已经发起审批
	                var strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","VerifyTradeIsFqSp",oTr[0].oid,"");
	                if(strReturn!="PASS")
	                {
	                    alert("审批状态为" + sApproveState + "，不允许进行审批操作！");    
	                   return false;
	                }	
				    
				}
				
                var strReturn = "";
                
                if (sType == "变更价格") {
                    //穿底价校验
                    strReturn = openXMLHTTP("/Slxt/XSXC/XSXC_XMLHTTP.aspx?salemodiapplyguid=" + oTr[0].oid, "ValidTotalLtDjTotal".toLocaleUpperCase());
                    if (strReturn === "Error") {
                        alert("操作失败，请与管理员联系！");
                    }else if (strReturn === "OK") {
                        alert("房间总价低于底价，不允许审批！");
                        return;
                    }
                    strReturn = OpenModalWin("价格变更审批","/Slxt/XSXC/Order_Sp.aspx?isFrom=sqd","",500,220);
                }
                else
                {
                    strReturn = OpenModalWin(sType + "审批","/Slxt/XSXC/Order_Sp.aspx?isFrom=sqd","",500,220);
                }                
	
                if(strReturn!=undefined&&strReturn.length==2) 
                {
                    strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","SetApplyAudit",oTr[0].oid,strReturn[0],strReturn[1]);
                    if (strReturn=="FAIL" || strReturn==undefined) 
                    {
	                    alert("审批失败，请与管理员联系！");
	                    return false;
                    }
                   appGrid.frameElement.Query();
                }
			}
			
			//发起审批
		    function ApproveFlow(sFlType) {
		        
    		    var oTr = appGrid.frameElement.getSelected();
	    	    if (!oTr) return;
    	    	
		        if (sFlType == "发起审批")
		        {
		            var sSaleType = oTr[0].SaleType;
		            var sReturn =  GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx?SaleType=" + escape(sSaleType), "CheckPowerFq", "", "");
		            if (sReturn == "FAIL")
		            {
		                alert("你没有" + sSaleType + "的变更申请权限！");
		                return false;
		            }

		            var sType = oTr[0].ApplyType + '审批';
		            if (sType == "变更价格审批") {
		                //穿底价校验
		                strReturn = openXMLHTTP("/Slxt/XSXC/XSXC_XMLHTTP.aspx?salemodiapplyguid=" + oTr[0].oid, "ValidTotalLtDjTotal".toLocaleUpperCase());
		                if (strReturn === "Error") {
		                    alert("操作失败，请与管理员联系！");
		                } else if (strReturn === "OK") {
		                    alert("房间总价低于底价，不允许审批！");
		                    return;
		                }
		                sType = "价格变更审批";
		            }


                    //注：需要传入真实的 房间信息 和 变更日期
                    StartupNewApproveProcess(oTr[0].oid, sType, oTr[0].cells[3].innerText,oTr[0].cells[7].innerText);
                    appGrid.frameElement.Query();
                 }
                 else if (sFlType == "审批过程")
                 {
                    ApproveProcess(oTr[0].oid);
                 }
            }
      
            //单击时切换状态
            function ChangeState() {
                
                // 选中行对象数组
				var oTr = appGrid.frameElement.getSelected();
				if (!oTr) return; 
    
                var arrSh = Form1.txtBgsign.value.split("|");
                var sBssign;
			    switch (oTr[0].ApplyType)
			    {
			        case "变更价格":
			            sBssign = arrSh[0];
			        break;
			        case "换房":
			            sBssign = arrSh[1];
			        break;
			        case "退房":
			            sBssign = arrSh[2];
			        break;
			        case "增减权益人":
			            sBssign = arrSh[3];
			            break;
			        case "特批折扣":
			            sBssign = arrSh[5];
			            break;
			    }

			    //如果申请类型为“特批折扣”
			    if (oTr[0].ApplyType === "特批折扣") {
			        switch (parent.appViewList.xmlurl.toLocaleUpperCase()) {
			            case "/Slxt/XSXC/SaleModiApply_Grid0.xml".toLocaleUpperCase():          //“待审批的变更申请”视图
			                
			                //如果“启用特批折扣审批”业务参数的模式为“启用工作流审批”
			                //否则“启用特批折扣审批”业务参数的模式为“启用审批”或“不启用”
			                if (sBssign === "2" && IsHaveBgSp === "1") {
			                    //如果当前业务变更存在状态为“草稿”的工作流表单，并且当前用户有审批权限，显示“审批（审批过程）
			                    //如果当前业务变更的工作流表单进行中止或归档之后，又进行了取消审批操作，并且当前用户有该模块的审批权限，还需要显示“审批（审批过程）”按钮
			                    //如果当前业务变更不存在流程状态为“草稿”的工作流表单或不存在工作流表单，并且当前用户有该模块的审批权限，还需要显示“审批（发起审批）”按钮
			                    if (oTr[0].ProcessStatus === "-3") {
			                        reDisplay("c11,c13");
			                        deDisplay("c10,c12");
			                    } else if ((oTr[0].ProcessStatus === "2" || oTr[0].ProcessStatus === "-1") && oTr[0].ApproveState === "待审批") {
			                        reDisplay("c11,c13");
			                        deDisplay("c10,c12");
			                    } else if (oTr[0].ProcessStatus === "" || oTr[0].ProcessStatus !== "-3") {
			                        reDisplay("c11,c12");
			                        deDisplay("c10,c13");
			                    } else {
			                        deDisplay("c11,c13");
			                        deDisplay("c10,c12");
			                    }

			                } else if (IsHaveBgSp === "1") {
			                    //如果当前业务变更不存在工作流表单或作废的工作流表单，并且当前用户有该模块的审批权限，还需要显示“审批”按钮
			                    //如果当前业务变更存在工作流表单，并且当前用户有该模块的审批权限，还需要显示“审批（审批过程）”
			                     if (oTr[0].ProcessStatus === "" || oTr[0].ProcessStatus === "-2") {
			                        reDisplay("c10");
			                        deDisplay("c11,c12,c13");
			                    } else {
			                        reDisplay("c11,c13");
			                        deDisplay("c10,c12");
			                    }
			                }
			                break;
			            case "/Slxt/XSXC/SaleModiApply_Grid3.xml".toLocaleUpperCase():          //“审批中的变更申请”视图
			                
			                //如果当前用户有该模块的审批权限，显示“审批（审批过程）”按钮
			                if (IsHaveBgSp === "1") {
			                    reDisplay("c11,c13");
			                } else {
			                    deDisplay("c11,c13");
			                }

			                break;
			            case "/Slxt/XSXC/SaleModiApply_Grid1.xml".toLocaleUpperCase():              //“审批通过的变更申请”视图

			                //“启用特批折扣审批”业务参数的模式为“启用工作流审批”
			                //如果当前业务变更存在已归档的工作流表单，并且当前用户有该模块的审批权限，还需要显示“审批（审批过程）”按钮
			                //“启用特批折扣审批”业务参数的模式为“启用审批”
			                //显示“取消审批”按钮
			                //如果当前业务变更存在已归档的工作流表单，并且当前用户有该模块的审批权限，还需要显示“审批（审批过程）”按钮
			                //“启用特批折扣审批”业务参数的模式为“不启用”
			                //同“审批通过的变更申请”视图中启用审批的模式
			                if (sBssign === "2" && IsHaveBgSp === "1") {
			                    if (oTr[0].ProcessStatus === "2") {
			                        reDisplay("c11,c13");
			                    } else {
			                        deDisplay("c11,c13");
			                    }
			                    deDisplay("c1");
			                } else {
			                    reDisplay("c1");
			                    if (oTr[0].ProcessStatus === "2") {
			                        reDisplay("c11,c13");
			                    } else {
			                        deDisplay("c11,c13");
			                    }
			                }

			                break;
			            case "/Slxt/XSXC/SaleModiApply_Grid2.xml".toLocaleUpperCase():              //“审批不通过的变更申请”视图

			                //“启用特批折扣审批”业务参数的模式为“启用工作流审批”
			                //如果当前业务变更存在被中止的工作流表单，并且当前用户有该模块的审批权限，还需要显示“审批（审批过程）”按钮
			                //“启用特批折扣审批”业务参数的模式为“启用审批”
			                //显示“取消审批”按钮
			                //如果当前业务变更存在被中止的工作流表单，并且当前用户有该模块的审批权限，还需要显示“审批（审批过程）”按钮
			                //“启用特批折扣审批”业务参数的模式为“不启用”
			                //同“审批通过的变更申请”视图中启用审批的模式
			                if (sBssign === "2" && IsHaveBgSp === "1") {
			                    if (oTr[0].ProcessStatus === "-1") {
			                        reDisplay("c11,c13");
			                    } else {
			                        deDisplay("c11,c13");
			                    }
			                    deDisplay("c12,c1");
			                } else {
			                    if (oTr[0].ProcessStatus === "-1") {
			                        reDisplay("c11,c13");
			                    } else {
			                        deDisplay("c11,c13");
			                    }
			                    reDisplay("c1");
			                    deDisplay("c12");
			                }
			                break;
			        }
			        return;
			    } 
			    //如果启用了工作流审批，并且审核状态为“已审批”，隐藏“取消审批”按钮
			    //否则显示“取消审批”按钮
			    if (sBssign == "2" && oTr[0].ApproveState == "已审批") {
			        deDisplay("c1");
			    }
			    else {
			        reDisplay("c1");
			    }

			    //判断当前业务对象是否存在不为“作废”的流程
			    var strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx", "GetProcessGUIDByContract", oTr[0].oid, "");
			    //如果存在流程
			    if (strReturn != undefined && strReturn != "") {
			        //当前用户如果有审批权限，显示“审批（审批过程）”按钮，隐藏“审批”、“发起审批”按钮
			        //否则隐藏“审批”、“审批（发起审批）”、“审批（审批过程）”按钮  
			        if (IsHaveBgSp == "1") {
			            reDisplay("c11,c13");
			            deDisplay("c10,c12");
			        }
			        else {
			            deDisplay("c10,c11,c12,c13");
			        }
			    }
			    else {
			        //如果审核状态不为“已执行”并且不为“已审批”
			        //否则隐藏“审批”、“审批（发起审批）”、“审批（审批过程）”按钮  
			        if (oTr[0].ApplyState != "已执行" && oTr[0].ApproveState != "已审批") {
			            //如果开启了工作流审批
			            if (sBssign == "2") {

			                var strIsHaveRight = IsHaveRgSq;
			                if (oTr[0].SaleType == "合同") {
			                    strIsHaveRight = IsHaveHtSq;
			                }
			                //如果有变更申请权限，显示“审批（审批过程）”按钮，隐藏“审批”、“发起审批”按钮
			                //否则隐藏“审批”、“审批（发起审批）”、“审批（审批过程）”按钮  
			                if (strIsHaveRight == "1") {
			                    reDisplay("c11,c12");
			                    deDisplay("c10,c13");
			                }
			                else {
			                    deDisplay("c10,c11,c12,c13");
			                }
			            }
			            else {
			                //当前用户如果有审批权限，显示“审批”按钮，隐藏“审批（发起审批）”、“审批（审批过程）”按钮  
			                if (IsHaveBgSp == "1") {
			                    reDisplay("c10");
			                    deDisplay("c11,c12,c13");
			                }

			            }
			        }
			        else {
			            deDisplay("c10,c11,c12,c13");
			        }
			    }

			    



            }

		    //换房房间解锁
		    function HfUnlock()
		    {
		        // 选中行对象数组
				var oTr = appGrid.frameElement.getSelected();
				if (!oTr) return;
				
				if (oTr[0].ApplyType != "换房")
				{
				    alert("该记录不是换房申请变更，不需要解锁！");
				    return false;
				}
		        
		        var strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","HfUnlock", oTr[0].nowroomguid, "");
				if (strReturn == "OK") 
				{
					alert("解锁成功！");
				}
				else
				{
					alert("解锁失败！");
				}
		    
		    }
		    
		    //作废按钮
		    function Zf() {
		        
		        // 选中行对象数组
				var oTr = appGrid.frameElement.getSelected();
				if (!oTr) return;
				
				var arrSh = Form1.txtBgsign.value.split("|");
                var sBssign;
			    switch (oTr[0].ApplyType)
			    {
			        case "变更价格":
			            sBssign = arrSh[0];
			        break;
			        case "换房":
			            sBssign = arrSh[1];
			        break;
			        case "退房":
			            sBssign = arrSh[2];
			        break;
			        case "增减权益人":
			            sBssign = arrSh[3];
			        break;
			        case "其它变更":
			            sBssign = arrSh[4];
			        case "特批折扣":
			            sBssign = arrSh[5];
			        break;
			    }
		        
		        if (sBssign == "2") {
		            var sApproveState;
		            sApproveState = openXMLHTTP("/Slxt/XSXC/XSXC_XMLHTTP.aspx?SaleModiApplyGUID=" + oTr[0].oid, "GetSaleApproveState");
		            if (sApproveState === "审批中") {
		                alert("该变更申请正在流程审批中，不允许作废！");
		                return false;
		            }
		        }
		        
		        var sPath = "/Slxt/XSXC/SaleModiApply_Zf.aspx";
	            var sReturn = OpenModalWin("作废" + oTr[0].ApplyType + "申请", sPath, "SaleModiApplyGUID=" + oTr[0].oid + "&ApplyType=" + escape(oTr[0].ApplyType) + "&RoomGuid=" + escape(oTr[0].nowroomguid), 470, 300);
	       
	            if(sReturn=="ZFOK")
	            {
		            appGrid.frameElement.Query();
	            }
	        }

	        //工作流处理后
	        function afterWorkflow(strProcessGUID) {
	            // 选中行对象数组
	            var oTr = appGrid.frameElement.getSelected();
	            if (!oTr) return;
	            appGrid.frameElement.Query(oTr[0].oid); 	// 刷新并定位网格id="appGrid"
	            
	        }

		    
		    
		</script>
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form runat="server" id="Form1">
			<asp:textbox id="txtBgsign" Runat="server" style="DISPLAY:none"></asp:textbox>
		</form>
		<table style="FONT-SIZE: 9pt" height="100%" cellSpacing="0" cellPadding="0" width="100%">

			<tr height="1">
				<td>
					<mnu:AppGridMenu id="appGridMenu" runat="server"  />
				</td>
			</tr>
			<tr>
				<td>
					<cnt:AppGrid id="appGrid" runat="server" multiselect="false" />
				</td>
			</tr>
		</table>
	</body>
</HTML>
